package com.newtouch.bxzs.business.statistics.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.business.statistics.model.bo.*;
import com.newtouch.bxzs.business.statistics.model.vo.ActivityAchievementListVO;
import com.newtouch.bxzs.business.statistics.model.vo.ActivityAchievementVO;
import com.newtouch.bxzs.business.statistics.model.vo.ActivityProductSaleRankingVO;
import com.newtouch.bxzs.common.base.model.ActivityAchievement;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 活动期业绩Mapper类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/3 9:29</td>
 * <td>tianshangzhu</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author tianshangzhu
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface ActivityAchievementMapper extends BaseMapper<ActivityAchievement> {

    /**
     * 查询活动期个人业绩信息汇总
     *
     * @param activityAchievementVO 查询活动期个人业绩信息汇总VO
     * @return 查询活动期个人业绩信息汇总BO
     */
    ActivityAchievementSummaryBO getActivityAchievementSummary(@Param("activityAchievementVO") ActivityAchievementVO activityAchievementVO);

    /**
     * 查看活动期个人业绩保单列表
     *
     * @param page                      分页参数
     * @param activityAchievementListVO 查看活动期个人业绩保单列表VO
     * @return IPage<ActivityAchievementPolicyBO>
     */
    IPage<ActivityAchievementPolicyBO> getActivityAchievementPolicyList(@Param("page") Page<ActivityAchievementPolicyBO> page, @Param("activityAchievementListVO") ActivityAchievementListVO activityAchievementListVO);

    /**
     * 查看活动期个人业绩详情
     *
     * @param policyNumber 保单号
     * @return 业绩保单详细BO
     */
    AchievementPolicyDetailBO getActivityAchievementDetail(@Param("policyNumber") String policyNumber);

    /**
     * 查看活动期个人业绩排名
     *
     * @param activityAchievementVO 查看活动期个人业绩排名查看活动期个人业绩排名VO
     * @param organizationCode      机构编码
     * @param rank                  排名
     * @return ActivityAchievementRankingBO
     */
    ActivityAchievementRankingBO getActivityPersonalRanking(@Param("activityAchievementVO") ActivityAchievementVO activityAchievementVO, @Param("array") String[] organizationCode, @Param("rank") Integer rank);

    /**
     * 查看活动期业绩排名
     *
     * @param activityAchievementVO 查看活动期业绩排名VO
     * @param organizationCode      机构编码
     * @param rank                  排行
     * @return List<ActivityAchievementRankingBO>
     */
    List<ActivityAchievementRankingBO> getActivityAchievementRanking(@Param("activityAchievementVO") ActivityAchievementVO activityAchievementVO, @Param("array") String[] organizationCode, @Param("rank") Integer rank);

    /**
     * 查看活动期产品销量汇总
     *
     * @param activityProductSaleRankingVO 查看活动期当前产品销量排名VO
     * @param organizationCode             机构编码
     * @return ActivityProductSaleRankingBO
     */
    ActivityProductSaleRankingBO getActivityProductSaleRanking(@Param("activityProductSaleRankingVO") ActivityProductSaleRankingVO activityProductSaleRankingVO, @Param("array") String[] organizationCode);

    /**
     * 查看活动期所有产品销量排名
     *
     * @param activityProductSaleRankingVO 查看活动期所有产品销量排名VO
     * @param organizationCode             机构编码
     * @param rank                         排名
     * @return List<ActivityProductSaleRankingBO>
     */
    List<ActivityProductSaleRankingBO> getActivityAllProductSaleRanking(@Param("activityProductSaleRankingVO") ActivityProductSaleRankingVO activityProductSaleRankingVO, @Param("array") String[] organizationCode, @Param("rank") Integer rank);

    /**
     * 根据营销活动Id查询活动主题
     *
     * @param activityId 活动Id
     * @return String 活动主题
     */
    @Select("SELECT\n" +
            "\ta.MARKETING_ACTIVITY_THEME \n" +
            "FROM\n" +
            "\tASSISTANT_MARKETING_ACTIVITY AS a \n" +
            "WHERE\n" +
            "\ta.MARKETING_ACTIVITY_ID = #{activityId}")
    String getActivityThemeById(@Param("activityId") String activityId);

    /**
     * 获取当前用户所在机构的三级机构下所有机构
     *
     * @param userJobNumber 用户工号
     * @return 机构Code
     */
    String getOrganizationCode(String userJobNumber);
}
